﻿using System;
using Generic = System.Collections.Generic;
using System.Collections;
using System.Text;

namespace XProject.Commons.BaseUtil
{
    public class CollectionUtils
    {
        private CollectionUtils()
        {
        }

        /// <summary>
        /// 把一个非范型的集合转换成范型的集合.
        /// </summary>
        /// <param name="coll"></param>
        /// <param name="toColl"></param>
        public static Generic.ICollection<T> TypedCollection<T>(ICollection coll)
        {
            Generic.ICollection<T> toColl = new Generic.List<T>();
            if (coll == null) return toColl;
            Type tType = typeof(T);
            foreach (object o in coll)
            {
                if (o.GetType() == tType) toColl.Add((T)o);
            }

            return toColl;
        }
    }
}
